package com.tool_stdy.others;

/**
 * Created by yan_li on 2016/1/27.
 */
public class TestEmen {
    enum TestInfo{
        ZHUANLI(1,"zhuanli"),
        LUNWEN(3,"lunwen"),
        CHENGJI(3,"chengji");
        private int type;
        private String name;

        TestInfo(int type,String name){
            this.type = type;
            this.name = name;
        }

        /**
         * 当拿到一个枚举成员之后通过调用其get方法获取该成员的type值
         * @return
         */
        public int getType() {
            return type;
        }

        /**
         * 当拿到一个枚举成员之后通过调用该方法获取成员的name值
         * @return
         */
        public String getName() {
            return name;
        }

        /**
         * 根据输入的type类型通过switch的方式获取所对应的枚举类型
         * @param type
         * @return
         */
        public static TestInfo getTestInf(int type){
            switch (type){
                case 1:
                    return ZHUANLI;
                case 2:
                    return LUNWEN;
                case 3:
                    return CHENGJI;
                default:
                    return null;
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(TestInfo.getTestInf(1).getType());
        System.out.println(TestInfo.CHENGJI.getName());
    }
}

